<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/8
 * Time: 16:15
 */
namespace common\models\forms;

use yii\base\Model;

class UploadForm extends Model{
    
    public $url;
    public function rules()
    {
        return [
            [['url'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
        ];
    }

    public function upload()
    {
        if ($this->validate()) {
            $this->url->saveAs('uploads/' . $this->url->baseName . '.' . $this->url->extension);
            return true;
        } else {
            return false;
        }
    }
}